package br.com.center.loja.ws.dto.converter;

import java.util.ArrayList;
import java.util.List;

import br.com.center.loja.model.Order;
import br.com.center.loja.ws.dto.OrderDTO;

public class OrderDTOConverter implements Converter<Order, OrderDTO> {

	private ClientDTOConverter clientConverter = new ClientDTOConverter();
	private OrderItemDTOConverter orderItemConverter = new OrderItemDTOConverter();

	@Override
	public OrderDTO to(Order element) {
		OrderDTO dto = new OrderDTO();
		dto.setClient(clientConverter.to(element.getClient()));
		dto.setCreation(element.getCreation());
		dto.setDiscount(element.getDiscount());
		dto.setPaymentForm(element.getPaymentForm());
		dto.setDiscount(element.getDiscount());
		dto.setItems(orderItemConverter.to(element.getItems()));

		return dto;
	}

	@Override
	public Order from(OrderDTO element) {
		Order order = new Order();
		order.setClient(clientConverter.from(element.getClient()));
		order.setCreation(element.getCreation());
		order.setDiscount(element.getDiscount());
		order.setPaymentForm(element.getPaymentForm());
		order.setDiscount(element.getDiscount());
		order.setPaymentForm(element.getPaymentForm());
		order.setPaymentForm(element.getPaymentForm());

		return order;
	}

	@Override
	public List<OrderDTO> to(List<Order> elements) {
		List<OrderDTO> result = new ArrayList<OrderDTO>();

		for (Order element : elements) {
			result.add(to(element));
		}

		return result;
	}

	@Override
	public List<Order> from(List<OrderDTO> elements) {
		List<Order> result = new ArrayList<Order>();

		for (OrderDTO element : elements) {
			result.add(from(element));
		}

		return result;
	}
}
